/**************************************************************************
 * Name         : PVRJPEG.h
 * Title        : PowerVR Jpeg encode and Decode API
 * Author       : Jason Rogers
 * Created      : 23/02/05
 *
 * Copyright   : 2005 by Imagination Technologies. All rights reserved.
 *             : No part of this software, either material or conceptual 
 *             : may be copied or distributed, transmitted, transcribed,
 *             : stored in a retrieval system or translated into any 
 *             : human or computer language in any form by any means,
 *             : electronic, mechanical, manual or other-wise, or 
 *             : disclosed to third parties without the express written
 *             : permission of Imagination Technologies Limited, Unit 8,
 *             : HomePark Industrial Estate, King's Langley, Hertfordshire,
 *             : WD4 8LZ, U.K.
 *
 * Description  :
 *
 * Platform     : 
 *

 Version	 	: $Revision: 1.10 $ 

 Modifications	:
 $Log: PVRJpeg.h,v $

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

 */

#ifndef _PVR_JPEG_H_
#define _PVR_JPEG_H_


#include "img_types.h"
#include "PVRReturnCode.h"
#include "PVRCodecAPI.h"

typedef struct
{
	IMG_UINT32	ui32Width;		/* Width of the image component */
	IMG_UINT32	ui32Height;		/* Height of the image component */
} COMP_INFO;


typedef int (*StreamFlushCallback)(void*, void*, int, int);

typedef struct 
{
    IMG_UINT8 *    pBsBuffer;
    int         bsByteLen;
    IMG_UINT8 *    pBsCurByte;
    int         bsCurBitOffset;
} PVR_BITSTREAM;

typedef struct 
{
	IMG_UINT32	ui32Width;		/* Width of the JPEG image */
	IMG_UINT32	ui32Height;		/* Height of the JPEG image */
	IMG_UINT32	ui32Components;	/* Number of compnents in the image ( 1 or 3 ) */
	COMP_INFO	sCompInfo[3];	/* Array containing component info */
} PVR_JPEG_INFO;

#ifdef __cplusplus
extern "C" {  
#endif


/* Decode API Functions */

/***********************************************************************************
 Function Name      : PVRJPGDecodeBegin
 Inputs             : hInstance
 Outputs            : 
 Returns            : PVRRC
 Description        : Marks the begining of JPEG decode
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGDecodeBegin( /*in */		PVR_INSTANCE	hInstance );

typedef PVRRC	(*fnPVRJPGDecodeBegin)( /*in */		PVR_INSTANCE	hInstance );

/***********************************************************************************
 Function Name      : PVRJPGDecodeHeader
 Inputs             : hInstance,pui8BitStreamBuffer
 Outputs            : pui32BytesRead,psJpegInfo
 Returns            : PVRRC
 Description        : Decoded marker segment and frame header from the JPEG bit stream
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGDecodeHeader( /*in */		PVR_INSTANCE	hInstance ,
										/*in */		IMG_UINT8*		pui8BitStreamBuffer ,
										/*out*/		IMG_UINT32*		pui32BytesRead,
										/*out*/		PVR_JPEG_INFO*	psJpegInfo );
typedef PVRRC (*fnPVRJPGDecodeHeader)( /*in */		PVR_INSTANCE	hInstance ,
										/*in */		IMG_UINT8*		pui8BitStreamBuffer ,
										/*out*/		IMG_UINT32*		pui32BytesRead,
										/*out*/		PVR_JPEG_INFO*	psJpegInfo );



/***********************************************************************************
 Function Name      : PVRJPGDecodeFrame
 Inputs             : hInstance,pui8BitStreamBuffer,psJpegInfo,hDestSurf
 Outputs            : pui34BytesRead
 Returns            : PVRRC
 Description        : Decoded a frame to the given surface
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGDecodeFrame(	/*in */		PVR_INSTANCE	hInstance ,
									 	/*in */		IMG_UINT8*		pui8BitStreamBuffer ,
										/*out*/		IMG_UINT32*		pui34BytesRead,
										/*in */		PVR_JPEG_INFO*	psJpegInfo ,
										/*in */		PVR_SURFACE		hDestSurf	);
typedef PVRRC (*fnPVRJPGDecodeFrame)(	/*in */		PVR_INSTANCE	hInstance ,
									 	/*in */		IMG_UINT8*		pui8BitStreamBuffer ,
										/*out*/		IMG_UINT32*		pui34BytesRead,
										/*in */		PVR_JPEG_INFO*	psJpegInfo ,
										/*in */		PVR_SURFACE		hDestSurf	);

/***********************************************************************************
 Function Name      : PVRJPGDecodeEnd
 Inputs             : hInstance
 Outputs            : 
 Returns            : PVRRC
 Description        : Marks the end of a JPEG decode
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGDecodeEnd(	/*in */		PVR_INSTANCE	hInstance );


typedef PVRRC	(*fnPVRJPGDecodeEnd)(	/*in */		PVR_INSTANCE	hInstance );


/***********************************************************************************
 Function Name      : PVRJPGEncodeBegin
 Inputs             : hInstance,psJpegInfo,ui32Quality
 Outputs            : 
 Returns            : PVRRC
 Description        : Marks the begining of a JPEG encode and sets up encoder
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGEncodeBegin(	/*in */		PVR_INSTANCE	hInstance ,
										/*in */		PVR_JPEG_INFO*	psJpegInfo ,
										/*in */		IMG_UINT32		ui32Quality	);

typedef PVRRC (*fnPVRJPGEncodeBegin)(	/*in */		PVR_INSTANCE	hInstance ,
										/*in */		PVR_JPEG_INFO*	psJpegInfo ,
										/*in */		IMG_UINT32		ui32Quality	);
/***********************************************************************************
 Function Name      : PVRJPGEncodeMarker
 Inputs             : hInstance
 Outputs            : ui8BitStreamBuffer,puiBytesWritten
 Returns            : PVRRC
 Description        : Writes a JPEG marker segment to the bit stream
							Max written 574 bytes
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGEncodeMarker( /*in */		PVR_INSTANCE	hInstance ,
                                       	/*in */ PVR_BITSTREAM       *pBitStream ,
                                        /*in */ StreamFlushCallback fStreamFlush,
                                        /*in */ void                *pStreamHandle);


typedef PVRRC (*fnPVRJPGEncodeMarker)( /*in */		PVR_INSTANCE	hInstance ,
                                       	/*in */ PVR_BITSTREAM       *pBitStream ,
                                        /*in */ StreamFlushCallback fStreamFlush,
                                        /*in */ void                *pStreamHandle);
/***********************************************************************************
 Function Name      : PVRJPGEncodeHeader
 Inputs             : hInstance
 Outputs            : ui8BitStreamBuffer,puiBytesWritten
 Returns            : PVRRC
 Description        : Writes a frame header to the bit stream
							Max written 21 bytes
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGEncodeHeader( /*in */		PVR_INSTANCE	hInstance ,
                                       	/*in */ PVR_BITSTREAM       *pBitStream ,
                                        /*in */ StreamFlushCallback fStreamFlush,
                                        /*in */ void                *pStreamHandle);

typedef PVRRC (*fnPVRJPGEncodeHeader)( /*in */		PVR_INSTANCE	hInstance ,
                                       	/*in */ PVR_BITSTREAM       *pBitStream ,
                                        /*in */ StreamFlushCallback fStreamFlush,
                                        /*in */ void                *pStreamHandle);


/***********************************************************************************
 Function Name      : PVRJPGEncodeFrame
 Inputs             : hInstance,hSourceSurf,ui32BufferSize
 Outputs            : pui8BitStreamBuffer,puiBytesWritten
 Returns            : PVRRC
 Description        : Encodes a frame and writes to the bit stream
	
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGEncodeFrame(	/*in */		PVR_INSTANCE	hInstance ,	
										/*in */		PVR_SURFACE		hSourceSurf,	
										/*in */ PVR_BITSTREAM       *pBitStream ,
                                        /*in */ StreamFlushCallback fStreamFlush,
                                        /*in */ void                *pStreamHandle);

typedef PVRRC (*fnPVRJPGEncodeFrame)(	/*in */		PVR_INSTANCE	hInstance ,	
										/*in */		PVR_SURFACE		hSourceSurf,	
										/*in */ PVR_BITSTREAM       *pBitStream ,
                                        /*in */ StreamFlushCallback fStreamFlush,
                                        /*in */ void                *pStreamHandle);

/***********************************************************************************
 Function Name      : PVRJPGEncodeEnd
 Inputs             : hInstance
 Outputs            : 
 Returns            : PVRRC
 Description        : Marks the end of the JPEG Encode
************************************************************************************/
PVRRC PVRCODEC_API	PVRJPGEncodeEnd(	/*in */		PVR_INSTANCE	hInstance );

typedef PVRRC(*fnPVRJPGEncodeEnd)(	/*in */		PVR_INSTANCE	hInstance );

typedef struct
{
	fnPVRInitialise			PVRInitialise;
	fnPVRDeinitialise		PVRDeinitialise;
	fnPVRSurfaceAllocate	PVRSurfaceAllocate;
	fnPVRSurfaceAllocateRaw	PVRSurfaceAllocateRaw;
	fnPVRSurfaceSync		PVRSurfaceSync;
	fnPVRSurfaceLock		PVRSurfaceLock;
	fnPVRSurfaceUnlock		PVRSurfaceUnlock;
	fnPVRSurfaceFree		PVRSurfaceFree;

	fnPVRJPGDecodeBegin		PVRJPGDecodeBegin;
	fnPVRJPGDecodeHeader	PVRJPGDecodeHeader;
	fnPVRJPGDecodeFrame		PVRJPGDecodeFrame;
	fnPVRJPGDecodeEnd		PVRJPGDecodeEnd;
	fnPVRJPGEncodeBegin		PVRJPGEncodeBegin;
	fnPVRJPGEncodeMarker	PVRJPGEncodeMarker;
	fnPVRJPGEncodeHeader	PVRJPGEncodeHeader;
	fnPVRJPGEncodeFrame		PVRJPGEncodeFrame;
	fnPVRJPGEncodeEnd		PVRJPGEncodeEnd;

} PVRJPEGAPI;


#ifdef __cplusplus
}
#endif

#endif
